/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.mzk.oai.repositoryManager;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author Martin Rehanek (rehan@mzk.cz)
 */
public abstract class AbstractEntityManager {

   protected EntityManager getEntityManager() {
        return JpaAccess.getEntityManager();
    }

    protected boolean isManagedEntity(Object entity) {
        try {
            return getEntityManager().contains(entity);
        } catch (IllegalArgumentException e) {
            return false;
        }
    }

    protected boolean isEmpty(Query query) {
        List result = query.getResultList();
        return result.isEmpty();
    }

    protected abstract String getEntityClassName();

    protected abstract String getEntityIdString(Object entity);
}
